package com.beagle.njddapp.core;

import com.beagle.njddapp.base.ApiService;
import com.beagle.njddapp.base.RetrofitHttp;
import com.beagle.njddapp.bean.UserInfoBean;
import com.beagle.njddapp.net.BaseHttpResponse;
import com.beagle.njddapp.net.HttpResponseObserver;
import com.beagle.njddapp.net.RxSchedulers;

/**
 * @author hxx
 * @date 2021-03-17 13:50
 */
public class UserService {

    public  static final String TOKEN="token";
    public  static final String ROLE="role";
    public  static final String PHONE="phone";
    public static  final int ROLE_FARMER=1; //农户
    public static  final int ROLE_OWNER=2;  //农机主
    public static  final int ROLE_DIRVER=3; //驾驶员
    public static  final int ROLE_OIL=4; //加油车驾驶员
    private String carId;

    public String getCarId() {
        return carId;
    }

    public void setCarId(String carId) {
        this.carId = carId;
    }

    private String token;
    private int role=-1;
    private UserInfoBean userInfoBean;
    private String phone;

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPhone() {
        if (userInfoBean!=null){
            return userInfoBean.getPhone();
        }
        return phone;
    }

    public void setUserInfoBean(UserInfoBean userInfoBean) {
        this.userInfoBean = userInfoBean;
        if (userInfoBean!=null){
            role=userInfoBean.getUserRole();
        }

    }

    public UserInfoBean getUserInfoBean() {
        if (userInfoBean==null){
            return  new UserInfoBean();
        }
        return userInfoBean;
    }

    public int getRole() {
        if (role!=0){
            return role;
        }
        if (userInfoBean!=null){
            return userInfoBean.getUserRole();
        }else {
            return role;
        }
    }

    public void setRole(int role) {
        this.role = role;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getToken() {
        return token;
    }

    private UserService(){

    }
    public static UserService getInstance(){
        return SingleInstance.userService;
    }

    public void clear() {
        role=-1;
        token="";
        userInfoBean=null;
    }


    private static class SingleInstance{
        private static UserService userService=new UserService();
    }
}
